﻿using JTG.ServiceInterface.InterfaceService;
using System;
using System.Reflection;

namespace JTG.ServiceInterface.Factory
{
    /// <summary>
    /// api桥接服务工厂
    /// </summary>
    public class HisBridgeFactory
    {
       
        public IHisBridgeService CreatePrintService(string funcName)
        {
            //加载程序集
            var assembly = Assembly.Load("JTG.ServiceInterface");

            foreach (var t in assembly.GetTypes())
            {
                var customAttributes = t.GetCustomAttributes(typeof(Attribute.FunctionName), true);
                if (customAttributes.Length <= 0) continue;

                //查找方法
                foreach (var attribute in ((Attribute.FunctionName[])customAttributes))
                {
                    if (!attribute.FcName.ToString().Equals(funcName)) continue;

                    if (t.FullName == null) return null;
                    var type = assembly.GetType(t.FullName);
                    return (IHisBridgeService)Activator.CreateInstance(type);
                }
            }

            return null;
        }
    }
}
